<%@ page import="com.wuming.caiwu.security.SecurityHander" %><%--
  Created by IntelliJ IDEA.
  User: hanfei
  Date: 18/6/27
  Time: 下午3:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${allServerPath}static/css/bootstrap.min.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/style.css">
    <link rel="stylesheet" href="${allServerPath}static/layui/css/public.css">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->

    <style>
        .tab_zp td span {
            font-weight: bold;
            color: #003399;
        }

        ::-moz-placeholder {
            color: #d4d4d4;
        }

        ::-webkit-input-placeholder {
            color: #d4d4d4;
        }

        :-ms-input-placeholder {
            color: #d4d4d4;
        }

        .layui-upload-img{
            width: 82px;
            height: 82px;
        }
        .layui-upload button{
            background: none;
            position: absolute;
            top: 10px;
            left: 4px;
            width: 82px;
            height: 82px;
            margin: 0;
            padding: 0;
        }
        .layui-upload-list img{
            display: block;
            margin: 0 auto;
        }

    </style>
</head>
<body>
<div style="padding: 15px;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>设置商品价格</legend>
    </fieldset>

    <form class="layui-form" action="" id="productForm">
        <div class="layui-row">
            <div class="layui-col-xs12">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">商品名</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="productName" placeholder="请输入商品名" autocomplete="off"
                                   class="layui-input"
                                   readonly
                                   value="${product['productName']}">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">价格</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="price" autocomplete="off"
                                   class="layui-input" readonly
                                   value="${product['price']}">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row">
            <div class="layui-col-xs12">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">采购价格</label>

                        <div class="form-group layui-input-inline">
                            <input type="text" name="tradePrice" autocomplete="off"
                                   class="layui-input"
                                   readonly
                                   value="${product['tradePrice']}">
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <c:forEach items="${rolePrices}" var="price">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">${price.roleName}</label>

                            <div class="form-group layui-input-inline">
                                <input type="text" name="roleId${price.roleId}" value="${price.rolePrice}" placeholder=""
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色佣金</label>

                            <div class="form-group layui-input-inline">
                                <input type="text" name="roleId${price.roleId}Commission" value="${price.commission}" placeholder=""
                                       autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </c:forEach>
        <input type="hidden" name="id" value="${product['id']}"/>
    </form>
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-form-item">
                <button class="layui-btn" type="button" name="btnSave" id="btnSave" lay-filter="btnSave">保存
                </button>
            </div>
        </div>
    </div>

</div>

<script src="${allServerPath}static/layui/layui/layui.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
<script src="${allServerPath}static/js/bootstrap.min.js" charset="utf-8"></script>
<script type="text/javascript" src="${allServerPath}static/js/bootstrapValidator.js"></script>
<script type="text/javascript" src="${allServerPath}static/js/common/date-util.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.config({
        base: '${allServerPath}static/layui/build/js/'
    }).extend({
        tinymce: 'tinymce/tinymce'
    }).use(['layer', 'form', 'laydate', 'jquery', 'upload','tinymce'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery;

        $("button[name='btnSave']").click(function () {
            var prices = '${rolePrices}';
            var pricesArr = JSON.parse(prices);
            var productId = $("input[name='id']").val();
            for(var i = 0 ; i < pricesArr.length ; i++){
                var roleId = pricesArr[i].roleId;
                console.log("当前角色=" + roleId);
                var currentRoleIdPrice = $("input[name='roleId"+ roleId +"']").val();
                console.log(currentRoleIdPrice);
                pricesArr[i]['rolePrice'] = currentRoleIdPrice;
                pricesArr[i]['productId'] = productId;
                var currentRoleIdCommission = $("input[name='roleId"+ roleId +"Commission']").val();
                pricesArr[i]['commission'] = currentRoleIdCommission;
            }
            $.ajax({
                type: 'post',
                url: '${allServerPath}web/pms/saveRolePrice.htmls',
                data: {
                    "productRolePriceArr": JSON.stringify(pricesArr)
                },
                dataType: 'JSON',
                success: function (data) {
                    if (data.success) {
                        layer.msg("保存成功.");
                    } else {
                        layer.msg(data.message);
                    }
                },
                error: function () {
                    layer.msg("保存失败.");
                }
            });
        });

    });
</script>
</body>
</html>
